<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport"
  content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>#(mainTitle??)</title> 
#@includeBaseCss()
<link rel="stylesheet" type="text/css" href="#(ctx)/res/uploadify/uploadify.css">
</head>

<body class="no-skin">
  <div class="main-container" id="main-container">
    <script type="text/javascript">
        // 检查 class=main-container这个div层是不是相对窗口固定。
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>

    <div class="page-content">
      <!-- 页面内容开始 -->
      <div class="widget-main">

        <form class="form-horizontal" id="validation-form" method="post">
            <input type="hidden" name="obj.id" id="id" value="#(item.id??)" />

         <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right"
              for="versionNo">首页显示分类:</label>

            <div class="col-xs-12 col-sm-9">
              <div class="clearfix">
                      <select name="os" id="os" class="span3">
                        <option value="1" #(item.os?? == '1'?'selected':'')>是</option>
                        <option value="0" #(item.os?? == '0'?'selected':'')>否</option>
                      </select>
              </div>
            </div>
        </div>

          <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right"
              for="versionNo">首页显示橱窗:</label>

            <div class="col-xs-12 col-sm-9">
              <div class="clearfix">
                    <select name="os" id="os" class="span3">
                        <option value="1" #(item.os?? == '1'?'selected':'')>是</option>
                        <option value="0" #(item.os?? == '0'?'selected':'')>否</option>
                      </select>
              </div>
            </div>
          </div>

          <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right"
              for="versionNo">服务页显示优惠:</label>

            <div class="col-xs-12 col-sm-9">
              <div class="clearfix">
               <select name="os" id="os" class="span3">
                        <option value="1" #(item.os?? == '1'?'selected':'')>是</option>
                        <option value="0" #(item.os?? == '0'?'selected':'')>否</option>
                      </select>
              </div>
            </div>
          </div>

          <div class="form-group" align="center">
            <label class="control-label col-xs-12 col-sm-3 no-padding-left"
              for="content">服务页显示温馨提示:</label>

            <div class="col-xs-12 col-sm-9">
              <div class="clearfix" >
                      <select name="os" id="os" class="span3">
                        <option value="1" #(item.os?? == '1'?'selected':'')>是</option>
                        <option value="0" #(item.os?? == '0'?'selected':'')>否</option>
                      </select>
              </div>
            </div>
          </div>


          <div class="clearfix form-actions" align="center">
            <div class="col-md-offset-3 col-md-9">
              <button id="submit-btn" class="btn btn-info" type="submit"
                data-last="Finish">
                <i class="ace-icon fa fa-check bigger-110"></i> 提交
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i> 重置
              </button>
            </div>
          </div>

        </form>
      </div>
      <!-- /.widget-main -->
    </div>
    <!-- /.page-content -->
  </div>
  <!-- /.main-container -->
  
  #@includeBaseJs()
  <script src="#(ctx)/res/ace-1.3.3/assets/js/ace-extra.js"></script>
     <script src="#(ctx)/res/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    
      jQuery(function($) {

    

        var $validation = true;


        
        $('#validation-form').validate({
          errorElement: 'div',//使用什么标签标记错误
          errorClass: 'help-block',//指定错误提示的css类名,可以自定义错误提示的样式
          focusInvalid: true,//提交表单后,未通过验证的表单会获得焦点
          //表单验证规则
          rules: {
            remark:{//id
              required: true//必填
            },
            status:{
              required: true,
              number:true
            } 
            
          },
          //自定义的提示信息
          messages: {
            remark:{
              required: "第一项不能为空",
            },
            status:{
              required: "自然不能为空",
              number:"自然必须为整数"
            } 
          },
          //可以给未通过验证的元素加效果,闪烁等
          highlight: function (e) {
            $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
          },
          //要验证的元素通过验证后的动作,
          success: function (e) {
            $(e).closest('.form-group').removeClass('has-error');
            $(e).remove();
          },
          //跟一个函数,可以自定义错误放到哪里
          errorPlacement: function (error, element) {
            if(element.is(':checkbox') || element.is(':radio')) {
              var controls = element.closest('div[class*="col-"]');
              if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
              else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
            }
            else if(element.is('.select2')) {
              error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
            }
            else if(element.is('.chosen-select')) {
              error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
            }
            else error.insertAfter(element.parent());
          },
          //通过验证后运行的函数,里面要加上表单提交的函数,否则表单不会提交
          submitHandler: function (form) {
            // $('#file_upload').uploadify('upload','*');
            var $form = $("#validation-form");
            var $btn = $("#submit-btn");
            
            //验证是否提交中，还未处理完
            if($btn.hasClass("disabled")) return;
            
            //准备要提交的数据
            var submitData =$form.serializeArray();
            console.log(submitData);
            // alert(submitData[3]);
            //禁用提交按钮避免重复提交
            $btn.addClass("disabled");
            //开始提交
            console.log(submitData);
            $.post("#(ctx)/slide/saveSlide", submitData,function(data) {
              //放开提交按钮
              $btn.removeClass("disabled");
              //处理返回结果
              if(data.code==0){
                    alert("ok");
                    window.parent.reloadGrid(); //重新载入
                    layer.msg("保存成功", {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    },function(){
                      //关闭弹出层
                      closeView();
                    });
                    
                  }else{
                    layer.msg(data.msg, {
                        icon: 2,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    },function(){ });
                    
                  }
            },"json");
            return false;
          },
          //验证不通过时执行
          invalidHandler: function (form) {
            layer.msg("信息填写有误，再检查一下", {
                  time: 2000 //2秒关闭（如果不配置，默认是3秒）
              },function(){ });
          }
        });
      });
      
      //关闭弹出层
      function closeView(){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭 
      }
      
    </script>
</body>
</html>